package copyengine.utils.commandQueue
{
	import copyengine.utils.UUIDFactory;

	public final class CECommandQueueManger
	{
		private static var _instance:CECommandQueueManger;

		public static function get instance():CECommandQueueManger
		{
			if (_instance == null)
			{
				_instance = new CECommandQueueManger();
			}
			return _instance;
		}

		private var currentExecuteQueueVector:Vector.<CECommandExecuteQueue>;

		public function CECommandQueueManger()
		{
			currentExecuteQueueVector = new Vector.<CECommandExecuteQueue>();
		}

		public function getExecuteQueueInstance():CECommandExecuteQueue
		{
			var queue:CECommandExecuteQueue = new CECommandExecuteQueue(UUIDFactory.instance.generateUUID());
			return queue;
		}

		public function startExecuteQueue(_queue:CECommandExecuteQueue):void
		{
			currentExecuteQueueVector.push(_queue);
			_queue.startExecuter();
		}

		public function onExecuteQueueFinish(_queue:CECommandExecuteQueue):void
		{
			for (var i:int = 0; i < currentExecuteQueueVector.length; i++)
			{
				if (_queue == currentExecuteQueueVector[i])
				{
					_queue.dispose();
					currentExecuteQueueVector.splice(i, 1);
					return;
				}
			}
		}

		public function onExecuterFinish(_uuid:String):void
		{
			for each (var queue:CECommandExecuteQueue in currentExecuteQueueVector)
			{
				if (queue.getUUID() == _uuid)
				{
					queue.onExecuterFinish();
					return;
				}
			}
		}

	}
}
